package com.cxf.servlet;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Administrator
 * 投票的Servlet
 * @param
 * @return
 */
@WebServlet("/Vote")
public class Vote extends HttpServlet {
	
	@Override
	public void init() throws ServletException {
		super.init();
		ServletContext context = this.getServletContext();
		context.setAttribute("basketball",0);
		context.setAttribute("run", 0);
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/html;charset=UTF-8");
		ServletContext context = this.getServletContext();
		if (request.getParameter("hobby").equals("0")) {
			int count = (int)context.getAttribute("basketball");
			count += 1;
			context.setAttribute("basketball",count);
		} else {
			int count = (int)context.getAttribute("run");
			count += 1;
			context.setAttribute("run",count);
		}
		response.getWriter().append("篮球:"+context.getAttribute("basketball"))
			.append(",跑步:"+context.getAttribute("run"));	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
